package com.dyb.demo.equals_hashcode;

/**
 * @author dyb
 * @Description 重写equals一定要重写hashCode, 两个对象equals相等，那么hashCode返回的值也要相等，HashMap中判断用
 * @date 2019/3/14 14:34
 */
public class Clazz {
    String key;

    public Clazz(String key) {
        this.key = key;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        return this.key.equals(((Clazz)obj).key);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}

class Test {
    public static void main(String[] args) {

    }

}
